use actix_web::{error, get, post, web, Error, HttpRequest, HttpResponse};
use datasource_connector::restful::{get_class, get_instance, get_instance_by_id, get_instances};
use model_graph_types::datasource::{QueryCondition, QueryExtention, QueryOptions};
use serde::{Deserialize, Serialize};
use serde_json::json;

#[get("/meta/class/{clazz}")]
pub async fn meta_get_class(
    state: web::Data<crate::AppState>,
    identifier_param: web::Path<String>,
    _req: HttpRequest,
) -> Result<HttpResponse, Error> {
    //
    let context = state.context.clone();
    //用户ID
    // let user_id = crate::services::get_user_id(&req)?;
    let clazz = identifier_param.into_inner();

    let res = get_class(context, &clazz)
        .await
        .map_err(|err| error::ErrorInternalServerError(err))?;

    Ok(HttpResponse::Ok().json(json!(res)))
}
